package com.gamex.findit.service.impl;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import com.gamex.findit.dao.ADImageMapper;
import com.gamex.findit.model.ADImage;
import com.gamex.findit.service.ADImageService;

/**
 * 광고이미지 서비스
 * @author james
 *
 */
@Service
public class ADImageServiceImpl implements ADImageService{
	
	private static final Logger logger = LoggerFactory.getLogger(ADImageServiceImpl.class);

	@Autowired ADImageMapper ADMapper;
	
	@Override
	public List<ADImage> getAD(ADImage ad) throws Exception{
		List<ADImage> result = null;
		try {
			result = ADMapper.selectAD(ad);
		} catch (Exception e) {
			logger.error(e.getMessage());
			throw e;
		}
		return result;
	}

	@Override
	public int getADCount(ADImage ad) throws Exception{
		int count = 0;
		try {
			count = ADMapper.selectADCount(ad);
		} catch (Exception e) {
			logger.error(e.getMessage());
			throw e;
		}
		return count;
	}

	@Override
	public ADImage getADView(ADImage adImage) throws Exception{
		ADImage result = null;
		try {
			result = ADMapper.selectADView(adImage);
		} catch (Exception e) {
			logger.error(e.getMessage());
			throw e;
		}
		return result;
	}

	@Override
	public void insertAD(ADImage ad) throws Exception{
		try {
			ADMapper.insertAD(ad);
		} catch (Exception e) {
			logger.error(e.getMessage());
			throw e;
		}
	}

	@Override
	public void updateAD(ADImage ad) throws Exception{
		try {
			ADMapper.updateAD(ad);
		} catch (Exception e) {
			logger.error(e.getMessage());
			throw e;
		}
		
	}

	@Override
	public void deleteAD(int AdId) throws Exception{
		try {
			ADMapper.deleteAD(AdId);
		} catch (Exception e) {
			logger.error(e.getMessage());
			throw e;
		}
		
	}

	@Override
	@Async
	public void hitViewCount(int adId) throws Exception{
		try {
			ADMapper.hitViewCount(adId);
		} catch (Exception e) {
			logger.error(e.getMessage());
			throw e;
		}
		
	}

}
